package com.wordsay.web.controller;

import com.jfinal.core.Controller;
import com.wordsay.context.Context;
import com.wordsay.entity.OverallAnalystResult;
import com.wordsay.web.context.WebContext;

/**
 * response the analyst data request
 * @author squirrelrao
 *
 */
public class DataController extends Controller {

	/**
	 * get the analyst process
	 */
	public void getAnalystProcess(){
		
		 String process = WebContext.isAnalysted ? "1" : "0";
		 
		 this.renderText(process);
		 
		 return;
		
	}
	
	/**
	 * response the overall analyst top items
	 */
	public void getOverallTopItems(){
		
		//	data : ['聊过天的同事','加入的群','加入的讨论组','总共说的话（句）','总共说了的词（个）']
		OverallAnalystResult result = Context.getInstance().getResource().getOverallAnalystResult();
		
		String data = "";
		
	    data += result.getDialogPersons().size() + "," + result.getDialogGroups().size() + "," + result.getDialogDicussions().size();
	    data += "," + result.getTotalTalkCount() + "," + result.getTotalWordsCount();
		
		this.renderText(data);
		
		return;
	}
	
	/**
	 * response the overall analyst top items
	 */
	public void getOverallTopItemsJson(){
		
		//	data : ['聊过天的同事','加入的群','加入的讨论组','总共说的话（句）','总共说了的词（个）']
		OverallAnalystResult result = Context.getInstance().getResource().getOverallAnalystResult();
		
		String data = "";
		
		data += this.jsonItem("聊过天的同事", String.valueOf(result.getDialogPersons().size()))+",";
		data += this.jsonItem("加入的群", String.valueOf(result.getDialogGroups().size()))+",";
		data += this.jsonItem("加入的讨论组", String.valueOf(result.getDialogDicussions().size()))+",";
		data += this.jsonItem("总共说了的话", String.valueOf(result.getTotalTalkCount() ))+",";
		data += this.jsonItem("总共用了的词", String.valueOf(result.getTotalWordsCount()));
		
	    data = "[" + data + "]";
		
		this.renderText(data);
		
		return;
	}
	
	
	private String jsonItem(String name,String value){
		
		return "{value:"+value+",name:'"+name+"'}";
	}
}
